home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / NetSprocketTest / aevt.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  5.1 KB  |  204 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            2/10/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <AppleEvents.h>
  29. #include <MacWindows.h>
  30.  
  31. #include "App.h"
  32. #include "Proto.h"
  33.  
  34.  
  35. extern Boolean            gDone;
  36.  
  37. AEEventHandlerUPP        gAEOpenUPP;
  38. AEEventHandlerUPP        gAEQuitUPP;
  39. AEEventHandlerUPP        gAEOpenDocUPP;
  40. AEEventHandlerUPP        gAEPrintDocUPP;
  41.  
  42.  
  43. //----------------------------------------------------------------------
  44. //
  45. //    AEInit - initialize all the core apple events
  46. //
  47. //
  48. //----------------------------------------------------------------------
  49.  
  50. OSErr AEInit(void)
  51. {    
  52.     OSErr        err = noErr;
  53.  
  54.     gAEOpenUPP         = NewAEEventHandlerProc(DoAEOpenApp);
  55.     gAEQuitUPP         = NewAEEventHandlerProc(DoAEQuitApp);
  56.     gAEOpenDocUPP    = NewAEEventHandlerProc(DoAEOpenDoc);
  57.     gAEPrintDocUPP    = NewAEEventHandlerProc(DoAEPrintDoc);
  58.     
  59.                                 //    install auto Open App
  60.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  61.                                 gAEOpenUPP, 0L, false );
  62.                                                     
  63.     if (err == noErr)            // install auto Quit App
  64.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  65.                                     gAEQuitUPP, 0L, false );
  66.         
  67.     if (err == noErr)            // install auto Open Document
  68.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  69.                                     gAEOpenDocUPP,0L,false);
  70.                                                         
  71.     if (err == noErr)            // install auto Print Document
  72.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  73.                                     gAEPrintDocUPP,0L,false);
  74.     
  75.                             
  76.     return err;
  77.                                                 
  78. }
  79.  
  80.  
  81. //----------------------------------------------------------------------
  82. //
  83. //    AERemove - remove all the allocated apple events
  84. //
  85. //
  86. //----------------------------------------------------------------------
  87.  
  88. OSErr AERemove(void)
  89. {    
  90.     OSErr        err = noErr;
  91.  
  92.     // deallocate all the core AppleEvents and assume that they are still around 
  93.     // since we shouldn't have removed them before now.
  94.     err = AERemoveEventHandler(kCoreEventClass, kAEOpenApplication, gAEOpenUPP, false);
  95.     err = AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, gAEQuitUPP, false);
  96.     err = AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, gAEOpenDocUPP, false);
  97.     err = AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments, gAEPrintDocUPP, false);
  98.  
  99.     DisposeRoutineDescriptor(gAEOpenUPP);
  100.     DisposeRoutineDescriptor(gAEQuitUPP);
  101.     DisposeRoutineDescriptor(gAEOpenDocUPP);
  102.     DisposeRoutineDescriptor(gAEPrintDocUPP);
  103.  
  104.     return err;
  105. }
  106.  
  107.  
  108. //----------------------------------------------------------------------
  109. //
  110. //    DoAEOpenApp - called by the Finder at launch time
  111. //
  112. //
  113. //----------------------------------------------------------------------
  114.  
  115. pascal OSErr DoAEOpenApp(AppleEvent *event,AppleEvent reply,long refCon)
  116. {
  117.                         
  118.     return noErr;
  119.         
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------
  124. //
  125. //     DoAEQuitApp -    called when the Finder asks app to quit
  126. //
  127. //
  128. //----------------------------------------------------------------------
  129.  
  130. pascal OSErr DoAEQuitApp(AppleEvent *event,AppleEvent reply,long refCon)
  131. {
  132.     #pragma unused( event, reply, refCon )
  133.  
  134.     // set the global quit flag
  135.     gDone = true;
  136.     
  137.     return noErr;
  138.         
  139. }
  140.  
  141.  
  142. //----------------------------------------------------------------------
  143. //
  144. //    DoAEOpenDoc - called when the Finder asks app to open a document
  145. //
  146. //
  147. //----------------------------------------------------------------------
  148.  
  149. pascal OSErr DoAEOpenDoc(AppleEvent *event,AppleEvent reply,long refCon)
  150. {
  151.     #pragma unused( event, reply, refCon )
  152.     
  153.  
  154.     return noErr;
  155.  
  156. }
  157.                 
  158.                                         
  159. //----------------------------------------------------------------------
  160. //
  161. //    DoAEPrintDoc - called when the Finder asks app to print a document
  162. //
  163. //
  164. //----------------------------------------------------------------------
  165.  
  166. pascal OSErr DoAEPrintDoc(AppleEvent *event,AppleEvent reply,long refCon)
  167. {
  168.     #pragma unused( event, reply, refCon )
  169.     
  170.  
  171.     return noErr;
  172.  
  173. }
  174.  
  175.  
  176. //----------------------------------------------------------------------
  177. //
  178. //    GotAEParams - make sure we got proper AE params for an Open 
  179. //                  Document from the Finder
  180. //
  181. //----------------------------------------------------------------------
  182.  
  183. OSErr GotAEParams(AppleEvent *appleEvent)
  184. {
  185.     OSErr            err;
  186.     DescType        type;
  187.     Size            size;
  188.     
  189.     err = AEGetAttributePtr(appleEvent,keyMissedKeywordAttr,
  190.                             typeWildCard,&type,nil,0,&size);
  191.                                             
  192.     if (err == errAEDescNotFound)
  193.         return(noErr);
  194.     
  195.     else
  196.     {
  197.         if (err == noErr)
  198.             return(errAEEventNotHandled);
  199.     }
  200.     
  201.     return err;
  202.  
  203.